import api from "../../../../common/api"

// pages/im/com/request-item/request-item.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    model: {
      type: Object,
      default: {}
    },
    targetAvatar: {
      type: String,
      default: "",
    },
    requestType: {
      type: String,
      default: ""
    },
    // 请求的日志id
    subId: {
      type: String,
      default: ""
    },
    cooperationId: {
      type: String,
      default: ""
    },
  },

  options: {
    styleIsolation: "apply-shared",
    addGlobalClass: true,
  },

  /**
   * 组件的初始数据
   */
  data: {

  },

  /**
   * 组件的方法列表
   */
  methods: {
    apiHandler(res) {
      return new Promise((resolve, reject) => {
        let param = {
          subId: this.data.subId  
        }
        if (this.data.requestType == 'copy_house') {
          param.askCopyResult = res
        } else {
          param.askExchangePhoneResult = res
        }
        api.updateCopyOrExchangeRecord(param, () => {
          resolve()
        })
      })
    },

    handleNo() {
      this.apiHandler(0).then(() => {
        this.triggerEvent('onresponse', {type: this.data.requestType, value: false, cooperationId: this.data.cooperationId})
      })
    },
    handleYes() {
      this.apiHandler(1).then(() => {
        this.triggerEvent('onresponse', {type: this.data.requestType, value: true, cooperationId: this.data.cooperationId})
      })
    }
  }
})
